var BASE_URL = 'http://jinzhidata.com/v2'

$(function () {
// 加载报告/资料 todo 此处一次性加载所有的，待修改
    // 加载分类
    $.ajax({
        url: BASE_URL + "/resource/type/list",
        type: "get",
        contentType: 'application/json',
        dataType: "json",
        success: function (response) {
            var typeData = response.data
            // 循环分类
            for (var i = 0; i < typeData.length; i++) {
                var resourceTypeName = typeData[i].resourceTypeName
                var html = ''
                var moreHref = BASE_URL + '/pc/resource_list.html?typeName=' + resourceTypeName
                html += '<div class="zhul_art clearfix">'
                html += '   <div class="zhul_artTopic">'
                html += '       <h2 class="zhul_art_line">' + resourceTypeName + '</h2>'
                html += '       <ul class="zhul_artList">'
                html += '           <li>|</li>'
                html += '           <li><h3><a href="' + moreHref + '" >查看更多</a></h3></li>'
                html += '           <li>|</li>'
                html += '       </ul>'
                html += '   </div>'
                html += '   <ul class="art-list clearfix">'
                $.ajax({
                    url: BASE_URL + "/resource/list",
                    data: {
                        typeName: resourceTypeName,
                        page: 0,
                        size: 5
                    },
                    type: "get",
                    contentType: 'application/json',
                    dataType: "json",
                    async: false,
                    success: function (response) {
                        var resourceData = response.data
                        for (var j = 0; j < resourceData.length; j++) {
                            var resourceName = resourceData[j].resourceName
                            var resourceCover = resourceData[j].resourceCover
                            var resourceHref = BASE_URL + "/pc/resource.html?resourceId=" + resourceData[j].resourceId
                            html += '<li>'
                            html += '   <a href="' + resourceHref + '" title="' + resourceName + '" cname="new_www" class="c_click_log">'
                            html += '       <img class="art-pic" src="/img/' + resourceCover + '" alt="' + resourceName + '">'
                            html += '       <p class="art-title">' + resourceName + '</p>'
                            html += '   </a>'
                            html += '</li>'
                        }
                    }
                })
                html += '</ul>'
                html += '</div>'
                console.log(html)
                $(".DOM").append(html)
            }
        }
    })

})
